package com.zzyl.nursing.controller.member;

import com.github.pagehelper.PageInfo;
import com.zzyl.common.constant.HttpStatus;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.po.NursingProject;
import com.zzyl.nursing.domain.po.Reservation;
import com.zzyl.nursing.domain.vo.ReservationVO;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Long> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Long count = reservationService.getCancelledReservationCount(userId);

        return R.ok(count);
    }


    @GetMapping("/countByTime")
    @ApiOperation("查询时间段的预约次数")
    public R<List<ReservationVO>> getCountByTime(@RequestParam("time") Long time) {

        List<ReservationVO> reservationVOList = reservationService.getCountByTime(time);


        return R.ok(reservationVOList);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public R add(@RequestBody Reservation reservation) {
        Long userId = UserThreadLocal.getUserId();
        reservation.setStatus(0);
        reservation.setCreateBy(userId+"");
        reservation.setUpdateBy(userId+"");
        int i = reservationService.insertReservation(reservation);
        return R.ok(i);
    }


    @GetMapping("/page")
    @ApiOperation("分页预约查询")
    public R list(Integer status) {
        startPage();
        List<Reservation> reservations=  reservationService.selectReservation(status);


         return R.ok( getDataTable(reservations));
    }


    @PutMapping("/{id}/cancel")
    public R cancelReservation(@PathVariable("id") Long id){
        int i= reservationService.cancelReservation(id);
        return R.ok(1);
    }

}